/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package semant.first_pass;

import javax.management.AttributeList;
import semant.Env;
import symbol.ClassInfo;
import symbol.Symbol;
import syntaxtree.ClassDecl;
import syntaxtree.ClassDeclExtends;
import syntaxtree.ClassDeclSimple;
import syntaxtree.VisitorAdapter;

/**
 *
 * @author Thiago
 */
class ClassDeclHandler extends VisitorAdapter {

    private Env env;

    private ClassDeclHandler(Env e)
    {
        super();

        env = e;
    }

    static void firstPass(Env e, ClassDecl cd) {
        ClassDeclHandler h = new ClassDeclHandler(e);

        cd.accept(h);
    }

    public void visit(ClassDeclSimple node)
    {
        Symbol name = Symbol.symbol(node.name.s);

        ClassInfo info = new ClassInfo(name);

        AttributeListHandler.firstPass(env, info, node.varList);

        MethodListHandler.firstPass(env, info, node.methodList);

        if(!env.classes.put(name, info))
            env.err.Error(node,new Object[]{"Nome de classe redefinido.","Simbolo: "+name});
    }

    public void visit(ClassDeclExtends node)
    {

        Symbol name = Symbol.symbol(node.name.s);

        ClassInfo info = new ClassInfo(name);

        Symbol namePai = Symbol.symbol(node.superClass.s);



        AttributeListHandler.firstPass(env, info, node.varList);

        MethodListHandler.firstPass(env, info, node.methodList);

        if(!env.classes.put(name, info))
            env.err.Error(node,new Object[]{"Nome de classe redefinido.","Simbolo: "+name});
    }

}
